package com.sluggard.security.manage.model.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sluggard.mp.model.entity.IdEntity;
import com.sluggard.mp.model.entity.StandardAuditEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 菜单管理
 * </p>
 *
 * @author lizheng
 * @since 2024-04-28
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_menu")
@Schema(name = "MenuEntity", description = "菜单管理")
public class MenuEntity extends StandardAuditEntity {

    private static final long serialVersionUID = 1L;

    @Schema(description = "父节点")
    @TableField(value = "parent_id",updateStrategy = FieldStrategy.ALWAYS)
    private Long parentId;

    @Schema(description = "标题")
    @TableField("title")
    private String title;

    @Schema(description = "图标")
    @TableField("icon")
    private String icon;

    @Schema(description = "重定向路径")
    @TableField("redirect_url")
    private String redirectUrl;

    @Schema(description = "编码")
    @TableField("code")
    private String code;

    @Schema(description = "访问路径")
    @TableField("path")
    private String path;

    @Schema(description = "页面组件")
    @TableField("component")
    private String component;

    @Schema(description = "是否显示")
    @TableField("hidden")
    private Boolean hidden;

    @Schema(description = "聚焦菜单")
    @TableField("active_menu")
    private String activeMenu;

    @Schema(description = "权限类型 0 目录 1 菜单 2 按钮")
    @TableField("type")
    private Integer type;

    @Schema(description = "是否显示{0:隐藏,1:显示}")
    @TableField("status")
    private Integer status;

    @Schema(description = "排序号")
    @TableField("sort_no")
    private Integer sortNo;

    @Schema(description = "子菜单")
    @TableField(value = "children", exist = false)
    private List<MenuEntity> children;

    public void addChild(MenuEntity node) {
        if(this.children == null){
            children = new ArrayList<>();
        }
        this.children.add(node);
    }
}

